Skip to content

ln: avoid unlinking destination before hard-link source validation#11400

Open
can1357 wants to merge 1 commit intouutils:mainfrom
can1357:ln-avoid-unlinking-destination-before-hard-link-source-validation
Open

ln: avoid unlinking destination before hard-link source validation#11400
can1357 wants to merge 1 commit intouutils:mainfrom
can1357:ln-avoid-unlinking-destination-before-hard-link-source-validation

Conversation

@can1357
Copy link
Contributor

@can1357 can1357 commented Mar 18, 2026

uutils ln -f unlinks an existing destination before attempting a hard link, so a missing source deletes the destination even though link creation fails.
GNU ln attempts linking first and only removes and retries when replacement is actually possible.

Reproduction Steps

touch /tmp/ln_dst && ln -f /tmp/nonexistent_source /tmp/ln_dst
# Expected (GNU): reports missing source, prints exit=1, and still lists /tmp/ln_dst
# Actual (uutils): reports hard-link creation failure, prints exit=1, and /tmp/ln_dst is missing

Impact

ln -f can silently destroy existing files when the source path is wrong or disappears, breaking GNU compatibility and causing data loss in scripts that rely on force-replace semantics.

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
Note: The gnu test tests/tail/tail-n0f is now being skipped but was previously passing.
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@can1357 can1357 force-pushed the ln-avoid-unlinking-destination-before-hard-link-source-validation branch from e6d5754 to 72e271a Compare March 19, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants